package com.tomvian.screens.transitions 
{
	import com.tomvian.screens.AbstractScreen;
	import com.tomvian.screens.AbstractTransition;
	import org.libspark.betweenas3.BetweenAS3;
	import org.libspark.betweenas3.easing.Quad;
	import org.libspark.betweenas3.tweens.ITween;
	/**
	 * SlideOut
	 * @author Tom Vian
	 */
	public class SlideOut extends AbstractTransition
	{
		//--------------------------------------------------------------------------
		//
		//  Properties
		//
		//--------------------------------------------------------------------------
		
		protected var _tween:ITween;
		
		protected var _outPos:Object;
		protected var _inPos:Object;
		
		protected var _time:Number;
		
		//--------------------------------------------------------------------------
		//
		//  Getters / Setters
		//
		//--------------------------------------------------------------------------
		
		//--------------------------------------------------------------------------
		//
		//  Constructor
		//
		//--------------------------------------------------------------------------
		
		public function SlideOut(time:Number = 0.5, stageWidth:Number = 800.0, toLeft:Boolean = false) 
		{
			_time = time;
			
			_outPos = { x: toLeft ? -stageWidth : stageWidth};
			_inPos = { x: 0 };
			
			_overlap = true;
			_inFront = false;
		}
		
		//--------------------------------------------------------------------------
		//
		//  Methods
		//
		//--------------------------------------------------------------------------
		
		override public function play(fromScreen:AbstractScreen, toScreen:AbstractScreen):void 
		{
			super.play(fromScreen, toScreen);
			
			swap();
			
			if (_tween) _tween.stop();
			
			if (_fromScreen.graphic.parent) _fromScreen.graphic.parent.addChild(_fromScreen.graphic);
			
			_tween = BetweenAS3.tween(_fromScreen.graphic, _outPos, _inPos, _time, Quad.easeInOut);
			_tween.onComplete = onTransitionComplete;
			_tween.play();
		}
		
		override protected function onTransitionComplete():void 
		{
			_fromScreen.graphic.x = 0;
			
			super.onTransitionComplete();
		}
	}
}